#ifndef __SUBSYSTEM_BLOCK_BEHAVIORS_H__
#define __SUBSYSTEM_BLOCK_BEHAVIORS_H__

#include "Subsystems/Subsystem.hpp"
#include "SubsystemBlockBehavior.hpp"
#include <unordered_map>
#include <vector>

namespace PocketSurvival
{
    class Block;
    class SubsystemBlockBehaviors : public Subsystem
    {
    protected:
        std::vector<SubsystemBlockBehavior *> m_blockBehaviorsByContents[1024];
        std::unordered_map<std::string, SubsystemBlockBehavior *> m_blockBehaviorMap;

    protected:
        void addSubsystemBlockBehavior(SubsystemBlockBehavior *blockBehavior);
        void matchBlockBehavior(Block *block);

    public:
        /**
         * @brief 通过方块的contents值获取其所有的方块行为
         * @param contents 方块的contents值
         * @return 方块的所有行为
         */
        std::vector<SubsystemBlockBehavior *> &getBlockBehaviors(int32_t contents);

        /**
         * @brief 获取所有方块的行为
         */
        inline const std::vector<SubsystemBlockBehavior *> *getBlockBehaviorsByContents();

    public:
        SubsystemBlockBehaviors();

        virtual void load(const nlohmann::json &json) override;

        virtual const std::string &getName() const override;
    };

    inline SubsystemBlockBehaviors::SubsystemBlockBehaviors() {}

    inline const std::vector<SubsystemBlockBehavior *> *SubsystemBlockBehaviors::getBlockBehaviorsByContents()
    {
        return m_blockBehaviorsByContents;
    }
}

#endif